package app.server.project.main.service.controller;

import app.server.project.core.http.RespModel;
import app.server.project.core.httpauth.UnAuth;
import app.server.project.main.service.dto.ADDto;
import app.server.project.main.service.dto.auth.CMSLoginReq;
import app.server.project.main.service.dto.auth.LoginResp;
import app.server.project.main.service.dto.auth.TGLoginReq;
import app.server.project.main.service.dto.auth.TGLoginResp;
import app.server.project.main.service.service.auth.AuthService;
import app.server.project.main.service.service.auth.tg.TGAuthService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 权限模块
 */
@AllArgsConstructor
@RestController
@RequestMapping("/auth")
public class AuthController {

    private AuthService authService;
    private TGAuthService tgAuthService;


    /**
     * 后台登录
     *
     * @param
     */
    @PostMapping("/cmsLogin")
    @UnAuth
    public RespModel<LoginResp> cmsLogin(@RequestBody CMSLoginReq req) {
        return RespModel.success(this.authService.cmsLogin(req));
    }

    /**
     * 纸飞机登录
     *
     * @param
     */
    @PostMapping("/tgLogin")
    @UnAuth
    public RespModel<TGLoginResp> tgLogin(@RequestBody TGLoginReq req, HttpServletRequest request) {
        return RespModel.success(this.tgAuthService.tgLogin(req, request.getRemoteAddr()));
    }

    /**
     * 广告用户检查
     *
     * @param
     */
    @RequestMapping("/chkTGUser/{openId}")
    @UnAuth
    public RespModel<ADDto> chkTGUser(@PathVariable long openId) {
        return RespModel.success(this.tgAuthService.chkTGUser(openId));
    }
}
